package com.app.twth.ui.returnsputatay;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.app.twth.app.Constant;
import com.app.twth.base.BaseAndroidViewModel;
import com.app.twth.bean.BaseResponseEntity;
import com.app.twth.bean.LoadingBean;
import com.app.twth.net.JsonCallBack;
import com.app.twth.ui.tally.lpn.TalliedSku;
import com.lzy.okgo.model.Response;

import java.util.List;


/**
 * ****************************************************************
 * 文件名称: LoginViewModel
 * 文件描述:
 * 注意事项:
 * 版权声明:
 * ****************************************************************
 */
public class ReturnsPutatayViewModel extends BaseAndroidViewModel<ReturnsPutatayDataModel> {
    public MutableLiveData<List<String>> lpnListMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<List<TalliedSku>> skuListMutableLiveData = new MutableLiveData<>();

    public ReturnsPutatayViewModel(@NonNull Application application) {
        super(application);
    }

    public void waitingPutawayIbLpns(int type) {
        isLoading.setValue(new LoadingBean(true, Constant.loading));
        errorResultCode.setValue("");
        mModel.waitingPutawayIbLpns(type, new JsonCallBack<BaseResponseEntity<List<String>>>() {
            @Override
            public void onSuccessData(Response<BaseResponseEntity<List<String>>> response) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                BaseResponseEntity<List<String>> baseResponseEntity = response.body();
                if (baseResponseEntity == null) {
                    return;
                }
                if (baseResponseEntity.getCode() == null) {
                    return;
                }
                if (baseResponseEntity.getCode().equals("200")) {
                    lpnListMutableLiveData.setValue(baseResponseEntity.data);
                    return;
                }
                infoResultMsg = baseResponseEntity.getMessage();
            }

            @Override
            public void onError(String error) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                infoResultMsg = error;
                errorResultCode.setValue(infoResultMsg);
            }
        });
    }

    public void getIbLpnSkuList(String lpn) {
        isLoading.setValue(new LoadingBean(true, Constant.loading));
        errorResultCode.setValue("");
        mModel.getIbLpnSkuList(lpn, new JsonCallBack<BaseResponseEntity<List<TalliedSku>>>() {
            @Override
            public void onSuccessData(Response<BaseResponseEntity<List<TalliedSku>>> response) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                BaseResponseEntity<List<TalliedSku>> baseResponseEntity = response.body();
                if (baseResponseEntity == null) {
                    return;
                }
                if (baseResponseEntity.getCode() == null) {
                    return;
                }
                if (baseResponseEntity.getCode().equals("200")) {
                    skuListMutableLiveData.setValue(baseResponseEntity.data);
                    return;
                }
                infoResultMsg = baseResponseEntity.getMessage();
            }

            @Override
            public void onError(String error) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                infoResultMsg = error;
                errorResultCode.setValue(infoResultMsg);
            }
        });
    }

}
